{extend name="normal_base" /}
{block name="navigation"}{/block}
{block name="css"}

{/block}
{block name="body"}
<div class="x-body">
    <form class="layui-form" id="from_id" method="POST" action="{:url('edit')}">
        <div class="layui-form-item">
            <label for="sign_company" class="layui-form-label">
                <span class="x-red">*</span>&nbsp;公司名称：
            </label>
            <div class="layui-input-inline">
                <input type="text" id="sign_company" name="sign_company" value="{$info.sign_company}" autocomplete="off" class="layui-input" lay-verify="required|m_sign_company">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="sign_company" class="layui-form-label">
                <span class="x-red">*</span>&nbsp;公司代码：
            </label>
            <div class="layui-input-inline">
                <input type="text" id="code" name="code" value="{$info.code}" autocomplete="off" disabled class="layui-input" lay-verify="required|m_code">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span style="" id="show-contract-number">录入后，不能被修改</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <div class="layui-input-block">
                <input type="hidden" name="id" value="{$info.id}">
                <button  class="layui-btn" lay-filter="edit" lay-submit="">
                    修改
                </button>

                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
{/block}

{block name="script"}
<script>
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form

        //自定义验证规则
        form.verify({
            m_sign_company:function (value) {
                //验证长度是否超出限制,50个字
                if(value.length > 255){
                    return '公司名称长度超出限制，最多 255 个字';
                }
            },
            m_code:function (value) {
                //验证长度是否超出限制,255个字
                var emReg = /^[a-zA-Z]{1,6}$/;
                if(!emReg.test(value)) {
                    return "公司代码只能输入1-6位字母!";
                }
            }
        });

        //监听提交
        form.on('submit(edit)', function(data){
            $("#from_id").ajaxSubmit({
                beforeSubmit:function () {
                    //表单提交前
                },
                success:function (data) {
                    //console.log(JSON.stringify(data));
                    if (data.code == 1) {
                        layer.msg(data.msg,{icon:5,time:1500});
                    } else {
                        layer.alert("修改成功", {icon: 6},function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            //刷新父层页面
                            parent.location.replace(parent.location.href);
                        });
                    }
                }
            });
            return false;
        });

        /*代码转大写*/
        $('#code').blur(function () {
            $('#code').val($('#code').val().toUpperCase());
        });
    });


</script>
{/block}